package com.example.demo.dao.people;

import com.example.demo.model.people.Employee;
import com.example.demo.model.people.Provider;
import com.example.demo.model.system.User;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface EmployeeDAO {
//    仓储部门负责人
    @Select("select * from employee where employee_dept=#{employee_dept}")
    List<Employee> getByEmployeeDept(Integer employee_dept);

    //    一对一查询
    @Select("select * from employee ")
    @Result(column = "employee_dept", property = "dict",
            one = @One(select = "com.example.demo.dao.system.DictDAO.getByEmployeeId",fetchType = FetchType.LAZY))
    public List<Employee> selectAll();

    //    一对一
    @Select("select * from employee where employee_id=#{employee_id}")
    List<Employee> getByEmployeeId(Integer employee_id);

    //    添加
    @Insert("insert into employee(employee_name,employee_gender,employee_phone,employee_dept) values(#{employee_name},#{employee_gender},#{employee_phone},#{employee_dept})")
    Integer addEmployee(Employee employee);

    //    删除
    @Delete("delete from employee where employee_id=#{employee_id}")
    Integer deleteById(Integer employee_id);

    //    修改
    @Result(column = "employee_dept",property = "dict_id")
    @Result(column = "employee_dept", property = "dict",
            one = @One(select = "com.example.demo.dao.system.DictDAO.getByEmployeeId",fetchType = FetchType.LAZY))
    @Update("update employee set employee_name=#{employee_name},employee_gender=#{employee_gender},employee_phone=#{employee_phone},employee_dept=#{employee_dept} where employee_id=#{employee_id}")
    Integer updateById(Employee employee);

    //  模糊查询
    @Select("<script>"+
            "select * from employee where" +
            "<if test=\"employee_dept !=null and employee_dept != ''\">"+
            "employee_dept=#{employee_dept}"+
            "</if>"+
            "<if test=\"employee_name !=null and employee_name != ''\">"+
            "and employee_name like CONCAT('%',#{employee_name},'%')"+
            "</if>"+
            "</script>")
    @Result(column = "employee_dept", property = "dict",
            one = @One(select = "com.example.demo.dao.system.DictDAO.getByEmployeeId",fetchType = FetchType.LAZY))
    public List<Employee> findEmployee(String  employee_name,Integer employee_dept) ;
}
